home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Tools 3
/
Amiga Tools 3.iso
/
grafik
/
raytracing
/
rayshade-4.0.6.3
/
fixes
/
fix023
< prev
next >
Wrap
Text File
|
1994-08-09
|
15KB
|
482 lines
From theseas!Princeton.EDU!cek Tue, 28 Jun 94 16:52:03 EET
Received: by kriton.UUCP (V1.16/Amiga)
id AA00000; Tue, 28 Jun 94 16:52:03 EET
Received: by theseas.ntua.gr with UUCP; Tue, 28 Jun 1994 15:30:38 +0300
Received: from nemesis.ics.forth.gr (nemesis.csi.forth.gr) by pythia.ics.forth.gr via FORTHnet with SMTP;
id AA25343 (5.65c/FORTH-ICS-3.0-MHS-7.0); Tue, 28 Jun 1994 14:55:29 +0300
Received: from eunet.EU.net by nemesis.ics.forth.gr via FORTHnet with SMTP;
id AA10498 (5.65c/ICS-1.1); Tue, 28 Jun 1994 14:47:15 +0300 (EET DST)
Received: (uunet@localhost) by eunet.EU.net (8.6.8/8.6.4) with UUCP id NAA06872 for ariadne!theseas!kriton!kyrimis; Tue, 28 Jun 1994 13:51:15 +0200
Received: from Princeton.EDU by relay2.UU.NET with SMTP
(rama) id QQwwfv14573; Tue, 28 Jun 1994 07:50:50 -0400
Received: from fs.Princeton.EDU by Princeton.EDU (5.65b/2.111/princeton)
id AA04294; Tue, 28 Jun 94 07:46:16 -0400
Received: by cs.Princeton.EDU (4.1/1.105)
id AA01584; Tue, 28 Jun 94 07:46:15 EDT
Received: from arthur.cs.purdue.edu by cs.Princeton.EDU (4.1/1.105)
id AA01530; Tue, 28 Jun 94 07:46:01 EDT
Received: from icarus.cs.purdue.edu (root@icarus.cs.purdue.edu [128.10.8.56])
by arthur.cs.purdue.edu (8.6.4/PURDUE_CS-1.3) with ESMTP
id <GAA19676> for <rayshade-users@cs.princeton.edu>; Tue, 28 Jun 1994 06:45:58 -0500
Received: from localhost (bj@localhost [127.0.0.1])
by icarus.cs.purdue.edu (8.6.4/PURDUE_CS-1.3) with SMTP
id <GAA02160> for <rayshade-users@cs.princeton.edu>; Tue, 28 Jun 1994 06:45:57 -0500
Organization: Institute of Computer Science, FORTH, P.O.Box 1385,
Heraklio, Crete, GR-711-10, Greece
tel.: +30 (81) 39 16 00, fax: +30 (81) 39 16 01
Message-Id: <199406281145.GAA02160@icarus.cs.purdue.edu>
Date: Tue, 28 Jun 1994 06:45:57 -0500
Errors-To: rayshade-users-request@cs.Princeton.EDU
Remailed-Date: Tue Jun 28 07:46:03 EDT 1994
From: bj@cs.purdue.edu (Ben Jackson)
To: rayshade-users@cs.Princeton.EDU (Rayshade List)
Subject: color raypaint under X
When I first built rayshade, I just needed it as a backend, so I didn't
try to built raypaint (I assumed it needed the GL library). Since then
I've become a rayshade addict, and I built raypaint last night. I was
disappointed to discover that it would only display grayscale images,
so I decided to fix it. :-)
I figured that the original author had punted on the 8bit color code
because of palette computations, so I just used a 6x6x6 standard
colormap (much like xv's 24 bit mode). At first I thought I was clever
and made an adaptive algorithm that took advantage of the fact that
blue and red aren't as "important" as green. It generated 6x7x5 color
maps as a first try. It took me a LONG time to figure out what that
doesn't work.
Like the grayscale code, it first tries to share the map, and backs
down (5x5x5 etc down to 2x2x2) if it can't get enough colors. If it
can't get a 2x2x2 set of colors in the default map, it starts over with
a private colormap. If it fails again, it falls back on the the
grayscale code (what the heck). Everyone I know with a 24bit
framebuffer also has the GL library, so I didn't worry about taking
advantage of 24bit Visuals (which should probably use DirectColor
anyway).
A 2x2x2 map is only 8 colors (duh), and the grayscale code insists on
at least 16 colors. 2x2x2 might be too small, but I decided I'd let
you guys decide if 3x3x3 or higher would be a more reasonable limit.
Since grayscale is useful on 8bit displays (giving more detail in some
cases than a 6x6x6 colormap), I decided to add an option to force the
gray map. This wasn't as straightforward as I'd hoped, since raypaint
uses the same option parser as rayshade, which doesn't need this option
(and even if it did, you might want to watch the rendering in grayscale
while still generating 24bit color output). I added a small check for
'-M' in raypaint/main.c. If it sees it, it sets the flag and removes
it from the options list. This is a hack, but I don't see a better way
to do it without also adding the option to rayshade.
While I was in the code, I fixed a bug in the Rectangle rendering
code. It was approximating the color of the whole rectangle as the
color of the lower left corner. I added the code to average the four
color values, which makes the scene look a bit more realistic while
it's still blocky (which makes it easier to find the regions you want
to refine). I did manage to resist the temptation to run the whole file
through GNU Indent, since that would make the diff's unreasonable.
Once again, I'm not on the rayshade-users list, so please reply to (or
at least Cc) me. Comments welcome.
--Ben
*** raypaint/main.c.orig Tue Jun 28 05:19:44 1994
--- raypaint/main.c Tue Jun 28 05:48:15 1994
***************
*** 31,36 ****
--- 31,37 ----
#include "picture.h"
void RSInitialize(), RSStartFrame();
+ int gray;
int
main(argc, argv)
***************
*** 65,71 ****
/*
* Render the image.
*/
! Render(argc, argv);
StatsPrint();
return 0;
}
--- 66,72 ----
/*
* Render the image.
*/
! Render(argc, argv, gray);
StatsPrint();
return 0;
}
***************
*** 100,109 ****
--- 101,126 ----
int argc;
char **argv;
{
+ int i;
+
/*
* Initialize variables, etc.
*/
RSSetup();
+ /*
+ * Steal the gray option, -M (mono, OK?)
+ */
+ gray = 0;
+ for (i = 1; i < argc; ++i) {
+ if ('-' != argv[i][0] || 'M' != argv[i][1]) {
+ continue;
+ }
+ gray = 1;
+ for (; i < argc; ++i) {
+ argv[i] = argv[i+1];
+ }
+ --argc;
+ }
/*
* Parse options from command line.
*/
*** raypaint/render.c.orig Tue Jun 28 05:44:07 1994
--- raypaint/render.c Tue Jun 28 05:46:07 1994
***************
*** 122,130 ****
int SuperSampleMode = 0;
#define SSCLOSED (SuperSampleMode + 1)
! Render(argc, argv)
int argc;
char **argv;
{
/*
* Do an adaptive trace, displaying results in a
--- 122,131 ----
int SuperSampleMode = 0;
#define SSCLOSED (SuperSampleMode + 1)
! Render(argc, argv, gray)
int argc;
char **argv;
+ int gray;
{
/*
* Do an adaptive trace, displaying results in a
***************
*** 148,154 ****
*/
TopRay.time = Options.framestart;
! GraphicsInit(Screen.xsize, Screen.ysize, "rayview");
/*
* Allocate array of samples.
*/
--- 149,155 ----
*/
TopRay.time = Options.framestart;
! GraphicsInit(Screen.xsize, Screen.ysize, "rayview", gray);
/*
* Allocate array of samples.
*/
*** raypaint/xgraphics.c.orig Sun Feb 9 22:03:51 1992
--- raypaint/xgraphics.c Tue Jun 28 05:45:59 1994
***************
*** 33,40 ****
GC gc;
Window win;
int screen_height;
! unsigned long graymap[256];
int max_colors;
double one_over_gamma = 0.4;
--- 33,41 ----
GC gc;
Window win;
int screen_height;
+ int gray;
! unsigned long colormap[256];
int max_colors;
double one_over_gamma = 0.4;
***************
*** 42,47 ****
--- 43,49 ----
* Sets the gray color map for the device. A 2.5 gamma map is used
* by default.
*/
+ static
setup_gray_gamma_map()
{
int cc, col;
***************
*** 49,54 ****
--- 51,57 ----
XColor xcolor;
+ gray = 1;
/* Use the default colormap if possible. */
if ( vis == DefaultVisualOfScreen( scrn ) )
cmap = DefaultColormapOfScreen( scrn );
***************
*** 67,77 ****
xcolor.blue= gamma_color;
if (!XAllocColor(dpy, cmap, &xcolor)) {
for (cc=0; cc < col; cc++)
! XFreeColors(dpy, cmap, &graymap[cc], 1, 0);
col = 0;
break;
}
! graymap[col] = xcolor.pixel;
}
if (col)
return;
--- 70,80 ----
xcolor.blue= gamma_color;
if (!XAllocColor(dpy, cmap, &xcolor)) {
for (cc=0; cc < col; cc++)
! XFreeColors(dpy, cmap, &colormap[cc], 1, 0);
col = 0;
break;
}
! colormap[col] = xcolor.pixel;
}
if (col)
return;
***************
*** 85,97 ****
exit(-2);
}
for(cc=0; cc < 256; cc++)
! if (!XAllocColorCells(dpy, cmap, False, NULL, 0, &graymap[cc], 1))
break;
max_colors = cc;
xcolor.flags= DoRed | DoGreen | DoBlue;
for(col=0; col < max_colors; col++) {
! xcolor.pixel= graymap[col];
gamma_color = (pow((float) col / (float) max_colors,
one_over_gamma) * 65536);
xcolor.red= gamma_color;
--- 88,100 ----
exit(-2);
}
for(cc=0; cc < 256; cc++)
! if (!XAllocColorCells(dpy, cmap, False, NULL, 0, &colormap[cc], 1))
break;
max_colors = cc;
xcolor.flags= DoRed | DoGreen | DoBlue;
for(col=0; col < max_colors; col++) {
! xcolor.pixel= colormap[col];
gamma_color = (pow((float) col / (float) max_colors,
one_over_gamma) * 65536);
xcolor.red= gamma_color;
***************
*** 101,109 ****
}
}
! GraphicsInit(xsize, ysize, name)
int xsize, ysize;
char *name;
{
int win_size;
XSetWindowAttributes attrs;
--- 104,181 ----
}
}
! /*****************************************************************
! * Sets the color map for the device. A 2.5 gamma map is used
! * by default, with a direct 6x7x5 colormap
! */
! static
! setup_color_gamma_map()
! {
! static int first_try = 1;
! int cc, col;
! int r, g, b;
! int done;
!
! XColor xcolor;
!
! /* Use the default colormap if possible. */
! if (first_try && vis == DefaultVisualOfScreen(scrn)) {
! cmap = DefaultColormapOfScreen(scrn);
! } else {
! cmap = XCreateColormap(dpy, RootWindowOfScreen(scrn),
! vis, AllocNone );
! }
!
! /* try to share with current colormap */
! xcolor.flags= DoRed | DoGreen | DoBlue;
! for (max_colors = 6; max_colors >= 2; --max_colors) {
! done = 1; /* gets unset on failure */
! col = 0;
! for (r = 0; r < max_colors; ++r) {
! xcolor.red = pow((float) r / (float) max_colors,
! one_over_gamma) * 65536;
! for (g = 0; g < max_colors; ++g) {
! xcolor.green = pow((float) g / (float) max_colors,
! one_over_gamma) * 65536;
! for (b = 0; b < max_colors; ++b) {
! xcolor.blue = pow((float) b / (float) max_colors,
! one_over_gamma) * 65536;
! if (!XAllocColor(dpy, cmap, &xcolor)) {
! for (cc=0; cc < col; cc++)
! XFreeColors(dpy, cmap, &colormap[cc], 1, 0);
! r = g = b = 99;
! done = 0;
! break;
! }
! colormap[col++] = xcolor.pixel;
! }
! }
! }
! if (done)
! break;
! }
! if (!done) {
! if (first_try) {
! /* go back and try with a private color map */
! first_try = 0;
! setup_color_gamma_map();
! }
! /* our smallest color set (2x2x2 = 8) is smaller than the
! * grayscale code (16), but we still try the gray map because
! * it might be able to share colors.
! */
! fprintf(stderr, "Could not create color map -- trying grayscale\n");
! setup_gray_gamma_map();
! return;
! }
! fprintf(stderr, "using standard %dx%dx%d colormap\n", max_colors, max_colors, max_colors);
! gray = 0;
! }
!
! GraphicsInit(xsize, ysize, name, gray)
int xsize, ysize;
char *name;
+ int gray;
{
int win_size;
XSetWindowAttributes attrs;
***************
*** 143,149 ****
scrn = ScreenOfDisplay( dpy, max_vis->screen );
gc = DefaultGCOfScreen( scrn );
! setup_gray_gamma_map();
XFree( (char *)vis_list );
}
--- 215,225 ----
scrn = ScreenOfDisplay( dpy, max_vis->screen );
gc = DefaultGCOfScreen( scrn );
! if (gray) {
! setup_gray_gamma_map();
! } else {
! setup_color_gamma_map();
! }
XFree( (char *)vis_list );
}
***************
*** 181,192 ****
int xp, yp;
unsigned char color[3];
{
- float bwvalue;
int val;
! bwvalue = ( 0.35*color[0] + 0.55*color[1] + 0.10*color[2] ) / 256.0;
! val = (int) ( bwvalue * max_colors );
! XSetForeground( dpy, gc, graymap[val] );
XFillRectangle( dpy, win, gc, xp, (screen_height - (yp + 1)),
1, 1 );
}
--- 257,274 ----
int xp, yp;
unsigned char color[3];
{
int val;
! if (gray) {
! val = (0.35*color[0] + 0.55*color[1] + 0.10*color[2]) / 256.0 * max_colors;
! } else {
! val = color[0] / 256.0 * max_colors;
! val *= max_colors;
! val += color[1] / 256.0 * max_colors;
! val *= max_colors;
! val += color[2] / 256.0 * max_colors;
! }
! XSetForeground( dpy, gc, colormap[val] );
XFillRectangle( dpy, win, gc, xp, (screen_height - (yp + 1)),
1, 1 );
}
***************
*** 200,211 ****
int xp, yp, xs, ys;
unsigned char ll[3], lr[3], ur[3], ul[3];
{
- float bwvalue;
int val;
! bwvalue = ( 0.35*ll[0] + 0.55*ll[1] + 0.10*ll[2] ) / 256.0;
! val = (int) ( bwvalue * max_colors );
! XSetForeground( dpy, gc, graymap[val] );
XFillRectangle( dpy, win, gc, xp, (screen_height - (yp + ys + 1)),
xs+1, ys+1 );
XFlush( dpy );
--- 282,302 ----
int xp, yp, xs, ys;
unsigned char ll[3], lr[3], ur[3], ul[3];
{
int val;
! ll[0] = (ll[0] + lr[0] + ur[0] + ul[0]) / 4;
! ll[1] = (ll[1] + lr[1] + ur[1] + ul[1]) / 4;
! ll[2] = (ll[2] + lr[2] + ur[2] + ul[2]) / 4;
! if (gray) {
! val = (0.35*ll[0] + 0.55*ll[1] + 0.10*ll[2]) / 256.0 * max_colors;
! } else {
! val = ll[0] / 256.0 * max_colors;
! val *= max_colors;
! val += ll[1] / 256.0 * max_colors;
! val *= max_colors;
! val += ll[2] / 256.0 * max_colors;
! }
! XSetForeground( dpy, gc, colormap[val] );
XFillRectangle( dpy, win, gc, xp, (screen_height - (yp + ys + 1)),
xs+1, ys+1 );
XFlush( dpy );
***************
*** 275,281 ****
{
XEvent event;
if (XCheckTypedEvent(dpy, Expose, &event)) {
! XSetForeground( dpy, gc, graymap[0] );
XFillRectangle( dpy, win, gc, event.xexpose.x, event.xexpose.y,
event.xexpose.width, event.xexpose.height );
XFlush( dpy );
--- 366,372 ----
{
XEvent event;
if (XCheckTypedEvent(dpy, Expose, &event)) {
! XSetForeground( dpy, gc, colormap[0] );
XFillRectangle( dpy, win, gc, event.xexpose.x, event.xexpose.y,
event.xexpose.width, event.xexpose.height );
XFlush( dpy );
----------
Administrivia: rayshade-users-request@cs.princeton.edu
Mailing list: rayshade-users@cs.princeton.edu